#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>

using namespace std;

class Solution {
public:
    int sumwei(int n)
    {
        int sum;
        while (n)
        {
            int t = n % 10;
            sum = t * t;
            n /= 10;
        }
        return sum;
    }
    bool isHappy(int n) {
        int slow = n, fast = sumwei(n);
        while (slow != fast)
        {
            slow = sumwei(slow);
            fast = sumwei(sumwei(fast));
        }
        return slow == 1;
    }
};